package com.amazon.ags.overlay;

import android.content.Context;
import android.os.Bundle;
import android.os.Message;
import android.os.RemoteException;
import android.util.Log;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.RemoteViews;
import com.amazon.ags.api.overlay.PopUpLocation;
import com.amazon.ags.client.AmazonGamesService;
import com.amazon.ags.client.GCResponseHandleImpl;
import com.amazon.ags.client.achievements.AchievementsService;
import com.amazon.ags.client.leaderboards.LeaderboardsService;

public class PopUpManager
{
  private static final String FEATURE_NAME = "AGS_OL";
  private static PopUpManager INSTANCE;
  private static final String TAG = "AGS_OL_" + PopUpManager.class.getSimpleName();
  private final AchievementsService achievementsService;
  private final AmazonGamesService amazonGamesService;
  private final Context context;
  private final LeaderboardsService leaderboardsService;
  private final PopUpPrefs preferences = PopUpPrefs.INSTANCE;

  private PopUpManager(Context paramContext, LeaderboardsService paramLeaderboardsService, AchievementsService paramAchievementsService, AmazonGamesService paramAmazonGamesService)
  {
    this.context = paramContext;
    this.leaderboardsService = paramLeaderboardsService;
    this.achievementsService = paramAchievementsService;
    this.amazonGamesService = paramAmazonGamesService;
  }

  public static PopUpManager getInstance()
  {
    if (INSTANCE == null)
      Log.e(TAG, "Be sure to call initialize() first");
    return INSTANCE;
  }

  public static PopUpManager initialize(Context paramContext, LeaderboardsService paramLeaderboardsService, AchievementsService paramAchievementsService, AmazonGamesService paramAmazonGamesService)
  {
    try
    {
      INSTANCE = new PopUpManager(paramContext, paramLeaderboardsService, paramAchievementsService, paramAmazonGamesService);
      PopUpManager localPopUpManager = INSTANCE;
      return localPopUpManager;
    }
    finally
    {
      localObject = finally;
      throw localObject;
    }
  }

  public void executePopUp(RemoteViews paramRemoteViews, int paramInt)
  {
    executePopUp(new PopUpContent(paramInt, paramRemoteViews, new Bundle()));
  }

  public void executePopUp(PopUpContent paramPopUpContent)
  {
    Log.d(TAG, "Entering executePopUp with content: " + paramPopUpContent);
    if (!this.preferences.isEnabled())
    {
      Log.d(TAG, "Pop-ups disabled, skipping pop-up");
      return;
    }
    PopUpPrefs localPopUpPrefs = PopUpPrefs.INSTANCE;
    AGSToast localAGSToast = new AGSToast(this.context, paramPopUpContent, localPopUpPrefs.getLocation(), localPopUpPrefs.getFadeInDuration(), localPopUpPrefs.getFadeOutDuration());
    localAGSToast.setOnClickListener(new AGOverlayClickListener(paramPopUpContent, localAGSToast));
    localAGSToast.show();
  }

  public void executeWelcomeBackPopUp(RemoteViews paramRemoteViews, int paramInt)
  {
    PopUpContent localPopUpContent = new PopUpContent(paramInt, paramRemoteViews, new Bundle());
    PopUpPrefs localPopUpPrefs = PopUpPrefs.INSTANCE;
    AGSToast localAGSToast = new AGSToast(this.context, localPopUpContent, PopUpLocation.BOTTOM_CENTER, localPopUpPrefs.getWelcomeBackFadeInDuration(), localPopUpPrefs.getWelcomeBackFadeOutDuration());
    localAGSToast.setOnClickListener(new AGOverlayClickListener(localPopUpContent, localAGSToast));
    localAGSToast.show();
  }

  public class AGOverlayClickListener
    implements View.OnClickListener
  {
    private final PopUpContent content;
    private final AGSToast overlay;

    public AGOverlayClickListener(PopUpContent paramAGSToast, AGSToast arg3)
    {
      this.content = paramAGSToast;
      Object localObject;
      this.overlay = localObject;
    }

    public void onClick(View paramView)
    {
      this.overlay.destroy();
      switch (this.content.getOverlayActionCode())
      {
      default:
        Log.d(PopUpManager.TAG, "No defined onClick action");
        return;
      case 1:
        PopUpManager.this.achievementsService.showAchievementsOverlay(new GCResponseHandleImpl(null));
        return;
      case 2:
        PopUpManager.this.leaderboardsService.showLeaderboardsOverlay(new GCResponseHandleImpl(null));
        return;
      case 0:
        String str = this.content.getOverlayData().getString("LEADERBOARD_ID");
        PopUpManager.this.leaderboardsService.showRanksOverlay(str, new GCResponseHandleImpl(null));
        return;
      case 3:
      }
      Message localMessage = Message.obtain();
      localMessage.what = 29;
      try
      {
        PopUpManager.this.amazonGamesService.sendMessage(localMessage);
        return;
      }
      catch (RemoteException localRemoteException)
      {
        Log.w(PopUpManager.TAG, "Error sending message to service: " + localRemoteException);
      }
    }
  }
}

/* Location:           E:\android\Toy Defense 2_dex2jar.jar
 * Qualified Name:     com.amazon.ags.overlay.PopUpManager
 * JD-Core Version:    0.6.2
 */